package cn.icanci.ladybird.config;

import cn.icanci.ladybird.common.exception.BusinessErrorException;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @author: icanci
 * @date: Created in 2020/10/9 9:39
 * @classAction: 错误相应控制器
 */
@Configuration
public class ErrorConfig implements ErrorPageRegistrar {
    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/api/v1/pub/user/404");
        ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/api/v1/pub/user/500");
        ErrorPage errorPageBusinessErrorException = new ErrorPage(BusinessErrorException.class, "/api/v1/pub/user/500");
        ErrorPage errorPageBadResult = new ErrorPage(HttpStatus.BAD_REQUEST, "/api/v1/pub/user/500");
        ErrorPage errorPageException = new ErrorPage(Exception.class, "/api/v1/pub/user/500");
        ErrorPage errorPageThrowable = new ErrorPage(Throwable.class, "/api/v1/pub/user/500");
        registry.addErrorPages(errorPage404, errorPage500, errorPageThrowable, errorPageBusinessErrorException, errorPageException, errorPageBadResult);
    }
}
